package com.igrowing.easyRpc.serializer;

import com.igrowing.easyRpc.spi.SpiLoader;

import java.util.HashMap;
import java.util.Map;

public class SerializerFactory {

    public static final Map<String,Serializer> KEY_SERIALIZER_MAP = new HashMap<String,Serializer>()
    {{
        put(SerializerKeys.JDK,new JdkSerializer());
        put(SerializerKeys.JSON,new JsonSerializer());
        put(SerializerKeys.HESSIAN,new HessianSerializer());
        put(SerializerKeys.KRYO,new KryoSerializer());
    }};
    /**
     * 默认序列化器
     */
    private static final Serializer DEFAULT_SERIALIZER = new JdkSerializer();

    /**
     * 获取实例
     *
     * @param key
     * @return
     */
    public static Serializer getInstance(String key) {
        return SpiLoader.getInstance(Serializer.class,key);
    }

}